//
//  RxEmptyDataSetEmbeddedTableViewDataSource.swift
//  live
//
//  Created by melvyn on 2018/8/22.
//  Copyright © 2018 NEET. All rights reserved.
//

import Foundation
import RxSwift
import RxCocoa
import Differentiator
import RxDataSources

class RxTableViewEmptyEmbeddedReloadDataSource<S: SectionModelType>: RxTableViewSectionedReloadDataSource<S> {
    
    private var currentItemsCount = 0
    
    var isEmpty: Bool {
        return currentItemsCount == 0
    }
    
    override func tableView(_ tableView: UITableView, observedEvent: Event<[S]>) {
        switch observedEvent {
        case let .next(events):
            guard let lastEvent = events.last else { return }
            currentItemsCount = lastEvent.items.count
        default: break
        }
        super.tableView(tableView, observedEvent: observedEvent)
    }
}


class RxCollectionViewEmptyEmbeddedReloadDataSource<S: SectionModelType>: RxCollectionViewSectionedReloadDataSource<S> {
    
    private var currentItemsCount = 0
    
    var isEmpty: Bool {
        return currentItemsCount == 0
    }
    
    override func collectionView(_ collectionView: UICollectionView, observedEvent: Event<[S]>) {
        switch observedEvent {
        case let .next(events):
            guard let lastEvent = events.last else { return }
            currentItemsCount = lastEvent.items.count
        default: break
        }
        super.collectionView(collectionView, observedEvent: observedEvent)
    }
}

